package spoon.bet365.task;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import spoon.bet365.domain.League;
import spoon.bet365.service.Bet365Service;

@Component
public class Bet365BasketballTask {

	Logger log = LoggerFactory.getLogger(Bet365BasketballTask.class);

	@Autowired
	@Qualifier("bet365BasketballService")
	private Bet365Service basketballService;

	private List<League> leagueList = new ArrayList<League>();

	/**
	 * 농구 경기를 가져온다.
	 */
	//@Scheduled(fixedDelayString = "${bet365.basketball.delay}")
	public void taskGame() {
		int linkSize = this.leagueList.size();

		if (linkSize == 0) {
			taskLeague();
			return;
		}
		
		League league = this.leagueList.remove(0);

		basketballService.getGame(league);
	}
	
	/**
	 * 농구 리그를 가져온다.
	 */
	public void taskLeague() {
		leagueList.addAll(basketballService.getLeague());
	}
}
